//
//  VisitorTableViewController.swift
//  sinaWeiBo
//
//  Created by smartlei on 15/10/14.
//  Copyright © 2015年 smartlei. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 用户登录标记
    private var userLogon = UserAccountViewModel().userLogon
    
    //创建访客视图
    var visitorView: VisitorView?

    override func loadView() {
       // print(userLogon)
        //根据登录情况设置设置登录界面：进行拦截
        userLogon ? super.loadView() : setupVisitorView()
    }
    
    private func setupVisitorView() {
        
        //赋值
        visitorView = VisitorView()
        
        //替换视图
        view = visitorView
        
        //添加注册按钮点击事件
        visitorView?.registerButton.addTarget(self, action: "registerButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        //添加登录按钮点击事件
        visitorView?.loginButton.addTarget(self, action: "loginButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        //添加navigationItem 的左边leftBarButtonItem
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "registerButtonClick")
        //添加navigationItem 的左边leftBarButtonItem
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "loginButtonClick")
    }
}
// MARK: - 按钮点击处理事件
extension VisitorTableViewController {
    
    //注册点击处理
    @objc private func registerButtonClick() {
        print("注册吧")
        
    }
    //登录点击处理
    @objc private func loginButtonClick() {
      //  print("登录吧")
        
        //1 创建控制器
        let rootVC = OAuthViewController()
        //2 创建跟控制器
        let nvc =   UINavigationController(rootViewController: rootVC)
        
        //3 弹出窗口
        presentViewController(nvc, animated: true) { () -> Void in
            
        }
    }    
}
